
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
void solve()
{
	string s1, s2;
	cin >> s1 >> s2;

	vector<int> v1, v2;//v1小,v2大
	bool ok = true;

	for (int i = s1.size() - 1; i >= 0; i--) v1.push_back(s1[i] - '0');
	for (int i = s2.size() - 1; i >= 0; i--) v2.push_back(s2[i] - '0');

	vector<int> ans;
	for (int i = 0, j = 0; i < v2.size(); i++, j++)//默认加一,内部特殊情况再加一,要让v2减完
	{
		int t1 = j < v1.size() ? v1[j] : 0;
		int t2 = i < v2.size() ? v2[i] : 0;
		if (t2 < t1)
		{
			if (i == v2.size() - 1) { ok = false; break; }
			t2 = v2[++i] * 10 + t2;
			if (t2 < t1) { ok = false; break; }

		}
		if (t2 - t1 >= 10) { ok = false; break; }//减去后还有两位相当于原来要求的那个数某个位有两位
		ans.push_back(t2 - t1);
		if (i == v2.size() - 1 && ((int)v2.size())-i-1 < ((int)v1.size())-j-1) { ok = false; break; }

	}

	if (ok)
	{
		ll res = 0,t=1;
		for (int i = 0; i < ans.size();i++,t*=10) res = (ll)ans[i]*t+res;
		cout << res;
	}
	else cout << -1;
	cout << '\n';


}

int main()
{
	close();
	int T; cin >> T;
	while (T--) solve();
	return 0;
}
